I still haven't tried using mysqli, because i wanna know first if it can be used using mssql server because I'm still planning to buy a license of mssql server
问题:
回答1:
Mysqli is specific to MySQL. If you want access to MSSQL, I'd recommend you use PDO, a PHP function set/statement which can generically access various database types using drivers for each type. To connect to a MSSQL database using PDO, you first need SQLSRV, the driver, which you can download from Microsoft here. To connect, you would use the following:
$handle = new PDO("sqlsrv:Server=$server;Database=$database", $username, $password);
To query:
$queryRef = $handle->query($query);
To read results, declaring $results
as a two-dimensional associative array, the first being the result number, the second being the column name:
$results = $queryRef->fetchAll(PDO::FETCH_ASSOC);
So $results[3]['id']
would be the value of the column 'id' of the third result.
You can find more examples on the PHP documentation page for PDO here. The great thing about PDO is that you can use the same code for different databases, you just need to change the driver, and possibly the queries.
回答2:
PHP does have an implementation of MSSQL, however it's not "object-oriented" in the way that mysqli is.
In addition, the SQL syntax does vary slightly between MSSQL and MySQL in specific circumstances such as when limiting the number of results:
MySQL:
SELECT * FROM table LIMIT 100
MSSQL:
SELECT TOP 100 * FROM table
I'd recommend using PDO instead of mysqli, as PDO supports both MySQL and MSSQL.
回答3:
No, mysqli is for MySql. See Mysqli documentation.