©
このドキュメントでは、 php中国語ネットマニュアル リリース
[#1] sideshowAnthony at google dot com [2015-07-23 23:51:21]
Here is a PDO helper class to get you started . . .
define('DB_MAIN', 'localhost|user1|pa55word|db1');
// Connect to database db1
$db = new my_db(DB_MAIN);
// Request "SELECT * FROM table1 WHERE a=16 AND b=22"
// Get an array of stdClass's
$rows = $db->fetchAll('SELECT * FROM table1 WHERE a=? AND b=?', 16, 22);
class my_db{
private static $databases;
private $connection;
public function __construct($connDetails){
if(!is_object(self::$databases[$connDetails])){
list($host, $user, $pass, $dbname) = explode('|', $connDetails);
$dsn = "mysql:host=$host;dbname=$dbname";
self::$databases[$connDetails] = new PDO($dsn, $user, $pass);
}
$this->connection = self::$databases[$connDetails];
}
public function fetchAll($sql){
$args = func_get_args();
array_shift($args);
$statement = $this->connection->prepare($sql);
$statement->execute($args);
return $statement->fetchAll(PDO::FETCH_OBJ);
}
}
(Phillipus - I don't know what nationality you are, but the word "moron" is pretty offensive in UK English. Thank you)
[#2] Phillipus [2015-07-11 08:33:49]
This is deprecated. Get a brain morans and stop using it.
Had to say it because this is still a top google result for "php mysql" and Someone has to deal with the crap code from the previous "php expert".
[#3] robertpas550 at hotmail dot com [2012-05-05 11:02:33]
New users are advised to use MySQL Improved mysqli_ functions rather than the older [replaced] mysql_ functions where applicable and subject the appropriate latest stable versions of Apache, php and MySQL, etc.