PDO和MySQL查询,与sqllite PostgreSQL,Oracle,MS SQL,ODBC等相同的查询?

For a long time I've been using MySQL and I'm using more MySQLi nowadays.

I'm thinking about switching to PDO or get more out of MySQLi. I don't know what will be better and how our future looks like, unfortunately :)

I've seen some examples online about PDO and have seen that CREATE, INSERT, DELETE, UPDATE query/functions are not the same.

example i need (depending on the query) to use :

$db->exec();
$db->execute();
$db->prepare();

Cause there are different ways to do the same it will make me personally confused and not easy to make a function or class of them.

My question here is if i can use the same query's with different databases or do i have to write my code depending on what database i use. I found this code online.. They are (almost but) not the same.

MySQL

$sql = "CREATE TABLE user (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(80) NOT NULL, 
email VARCHAR(50) NOT NULL, 
PRIMARY KEY (id))";

$mysql->exec($sql);

SQLLite

$sql = "CREATE TABLE books(
id int,
title varchar(255),
author varchar(255))";

$sqllite->exec($sql);

Do i miss something? Am i seeing this wrong? Can i write the same code for different databases? UPDATE, INSERT, DELETE, CREATE, DROP

Everybody writes positive about PDO... I am always seeing things different :) Maybe someone can share his opinion or awnser my question to start with, before to jump into something new. Thanks

dongtu9823
dongtu9823 这个可能会说服你:与PDO相比,mysqli的可用性问题
大约 4 年之前 回复
dongmo8943
dongmo8943 PDO可以连接到不同的数据库。Mysqli只能连接到mysql。您编写的查询必须与它们要访问的数据库的语法相匹配。例如从用户中选择前5位用户将使用mssql,但是将使用来自用户限制5的select用户中断mysql,反之亦然
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐