PHP - Mysql

php

http://phpmaster.com/migrate-from-the-mysql-extension-to-pdo
http://www.php.net/manual/en/mysqli.overview.php MySQLi
http://phpmaster.com/avoid-the-original-mysql-extension-1
http://net.tutsplus.com/tutorials/php/real-world-oop-with-php-and-mysql/
http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
http://net.tutsplus.com/tutorials/php/php-database-access-are-you-doing-it-correctly/

How can we work with database?

$dbconx = @mysql_connect(IPAddress, username, password);

if (! @mysql_select_db("jokes")) {
    echo "Unable to locate the jokes database.";
    exit();
}

mysql_query($query, $dbconx);

while ($row = mysql_fetch_array($result)) {
    echo $row['JokeText'];
}

In the above code, the @ symbol infront of mysql_connect tell it to fail silently if it is not able to connect to the database, and in that case, the variable $dbconx has the value of false, and we can use it to determine if the connection was successful or not.

How can we check if there was an error?

$error_str = mysql_error();

How can we determine the number of affected rows?

For DELETE, INSERT, and UPDATE queries, MySQL also keep track of the number of rows affected:

$affected_rows = mysql_affected_rows();
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License