![]() $pdo->exec( 'USE db' ) Įxec() returns no data, but does return an integer count of modified/deleted rows. If credentials are good for the other database, switch with USE. $pdo->exec() can execute SQL in a single function call. Set default for convenience, and override as needed. ![]() Two main fetch modes: PDO::FETCH_ASSOC and PDO::FETCH_OBJ. Throw new PDOException($e->getMessage(), (int)$e->getCode()) $pdo = new PDO($dsn, $user, $pw, $options) PDO::ATTR_EMULATE_PREPARES => false // Emulation OFF is usually best. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // Throw exceptions automatically. $dsn = " mysql:host=$host dbname=$db charset=$charset port=$port" ![]() MySQL's utf8 charset had limited unicode support, so utf8mb4 is recommended., $host = '' Remote host - (port number specified) $pdo= new PDO( 'mysql:host=somehost port=12345 dbname=database', 'acct', 'pw' ) $pdo= new PDO( 'mysql:host=localhost dbname=database', 'acct', 'pw' ) PDO requires the database as part of the host string, and throws an error if it's missing. To see list of drivers the server: foreach( PDO::getAvailableDrivers() as $db) echo $db. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |