Skip to content

Instantly share code, notes, and snippets.

@chopf
Last active April 24, 2016 02:20
Show Gist options
  • Save chopf/7d9d7c7c4673624a0205 to your computer and use it in GitHub Desktop.
Save chopf/7d9d7c7c4673624a0205 to your computer and use it in GitHub Desktop.
mysql to pdo conversions
COMMANDS
MySQL PDO Notes
$result = mysql_query($queryStr) $pdoStatement = $pdo->query($queryStr)
mysql_fetch_array($result,$type = MYSQL_BOTH) $pdoStatement->fetch($type = PDO::FETCH_BOTH)
mysql_error() NO EXACT EQUIVALENT $pdo->errorInfo() returns an array, [0=>ErrorCode,1=>Driver specific error code,2=>driver specific error message]
mysql_insert_id() $pdo->lastInsertId()
mysql_free_cursor() NO EXACT EQUIVALENT $pdoStatement->closeCursor() is similar but on statement not PDO
mysql_select_db($dbName) NO EQUIVALENT PDO does not allow databases to be changed, you must create a new PDO connection, or if the info is the same you an use dot notation to query a different database
mysql_real_escape_string($stringToEscape) $pdo->quote($stringToEscape) PDO::quote will add the quotes for you!!!!
CONSTANTS
MySQL PDO
MYSQL_BOTH PDO::FETCH_BOTH
MYSQL_ASSOC PDO::FETCH_ASSOC
MYSQL_NUM PDO::FETCH_NUM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment