It returns the maximum length of a field in a recordset
Example
<?php
mysql_connect(“localhost”, “root”, “phpcode”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
echo mysql_field_len(mysql_query(“SELECT * FROM users”),1);
?>
Output
255
It returns the flags associated with a field in a record set
Example
<?php
mysql_connect(“localhost”, “root”, “phpcode”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
echo mysql_field_flags(mysql_query(“SELECT * FROM users”),1);
?>
Output
not_null
It returns a row from a recordset as a numeric array
Example
<?php
mysql_connect(“localhost”, “root”, “password”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
$userQry = mysql_query(“SELECT * FROM users”);
while($userInfo = mysql_fetch_row($userQry)){
print_r($userInfo);
}
?>
Output
Array
(
[0] => 1
[1] => PHP
)
Array
(
[0] => 2
[1] => JS
)
Array
(
[0] => 3
[1] => HTML
)
Array
(
[0] => 4
[1] => AS
)
It returns a row from a recordset as an object
Example
<?php
mysql_connect(“localhost”, “root”, “password”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
$userQry = mysql_query(“SELECT * FROM users”);
while($userInfo = mysql_fetch_object($userQry)){
print_r($userInfo);
}
Output
stdClass Object
(
[id] => 1
[name] => PHP
)
stdClass Object
(
[id] => 2
[name] => JS
)
stdClass Object
(
[id] => 3
[name] => HTML
)
stdClass Object
(
[id] => 4
[name] => AS
)
It returns the length of the contents of each field in a row.
Example
<?php
mysql_connect(“localhost”, “root”, “password”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
print_r(mysql_fetch_lengths(mysql_query(“SELECT * FROM users”)));
?>
It returns column info from a recordset as an object
MySQL table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | JS |
| 3 | HTML |
| 4 | AS |
+—-+——+
Example
<?php
mysql_connect(“localhost”, “root”, “password”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
$userQry = mysql_query(“SELECT * FROM users”);
while($userInfo = mysql_fetch_field($userQry)){
print_r($userInfo);
}
?>
Output
stdClass Object
(
[name] => id
[table] => users
[def] =>
[max_length] => 1
[not_null] => 1
[primary_key] => 1
[multiple_key] => 0
[unique_key] => 0
[numeric] => 1
[blob] => 0
[type] => int
[unsigned] => 0
[zerofill] => 0
)
stdClass Object
(
[name] => name
[table] => users
[def] =>
[max_length] => 4
[not_null] => 1
[primary_key] => 0
[multiple_key] => 0
[unique_key] => 0
[numeric] => 0
[blob] => 0
[type] => string
[unsigned] => 0
[zerofill] => 0
)
It returns a row from a recordset as an associative array
MySQL table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | JS |
| 3 | HTML |
| 4 | AS |
+—-+——+
Example
<?php
mysql_connect(“localhost”, “root”, “password”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
$userQry = mysql_query(“SELECT * FROM users”);
while($userInfo = mysql_fetch_assoc($userQry)){
print_r($userInfo);
}
?>
Output
Array
(
[id] => 1
[name] => PHP
)
Array
(
[id] => 2
[name] => JS
)
Array
(
[id] => 3
[name] => HTML
)
Array
(
[id] => 4
[name] => AS
)
It returns a row from a recordset as an associative array and/or a numeric array
MySQL table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | JS |
| 3 | HTML |
| 4 | AS |
+—-+——+
Example
<?php
mysql_connect(“localhost”, “root”, “password”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
$userQry = mysql_query(“SELECT * FROM users”);
while($userInfo = mysql_fetch_array($userQry)){
print_r($userInfo);
}
?>
Output
Array
(
[0] => 1
[id] => 1
[1] => PHP
[name] => PHP
)
Array
(
[0] => 2
[id] => 2
[1] => JS
[name] => JS
)
Array
(
[0] => 3
[id] => 3
[1] => HTML
[name] => HTML
)
Array
(
[0] => 4
[id] => 4
[1] => AS
[name] => AS
)
It’s deprecated .Escapes a string for use in a mysql_query
It returns the error description of the last MySQL operation
Example
<?php
$conn = mysql_connect(“localhost”, “root”, “password”) or die(mysql_error());
?>
Zend | Magento Certified PHP | eCommerce Architect