I tested a simple Php program using Sqlite3 instead of mySQL on my own computer and it works fine. What the program does is simple insert of record into a certain table. Now, when I try to do that on a remote web server running on Linux (CentOS) with Sqlite3 enabled it does not work.
I thought at first it was simply a file permission issue since my Sqlite file had an initial permissions of 644 so I changed it to 646 then 767 both to no avail.
The Php version by the way on web server is a little bit dated, namely, Php 5.1.6 but on my local PC it is 5.5.11.
This is the sample code that I ran on both servers.
$db = new PDO('sqlite:test.db');
$lastname = "Doe";
$firstname = "John";
$sql = "INSERT INTO people (Lastname,Firstname) VALUES (:lastname,:firstname)";
$q = $db->prepare($sql);
$q->execute(array(':lastname'=>$lastname,
':firstname'=>$firstname));
I tried a simple query on a sqlite3 database on the webserver by the way and it works.
So, could this be a simple Php version issue?
I cannot by the way change the php.ini so forgo that possible direction for the moment. And I don't have any choice of having a new Php version on that server since I use it for free.
I have PHP installed on a web server and also have MySQL on the same server and all works perfectly.
I now have SQL Server 2005 installed on another server 192.168.90.250 that I want to connect to as there is a view i want to display in PHP.
I have read around for a number of days but still can not get a connection to work.
I am running on the web server:
Windows Server 2008 R2
Apache 2.2
P 5.3.0
And SQL Server 2005 on another server
I presume I need to download a driver like SQLSRV30 and place the correct .dll file into the C:\Program Files (x86)\PHP\ext directory.
I presume I then need to edit the php.ini file and add something like the following:
extension=php_sqlsrv_53_ts.dll
I would then need to restart the apache server.
At this point I presume I would be able to use something like the following to connect to SQL Server:
<?php
if (function_exists('mssql_connect')) {
die("Your PHP installation does not have MSSQL support.");
}
$db = mssql_connect ($hostname, $username, $password);
if($db){
echo "no connection";
}else{
echo "connected";
}
?>
It seems as if I can not run the function mssql_connect, as the page just displays a blank page.
If I comment out the:
//$db = mssql_connect ($hostname, $username, $password);
the page at least displays some data.
I have literally spent days on this, what am I doing wrong?
Am I using the correct driver as there are different versions?
Thanks for your help.
D
For using the sqlsrv extension you need to use sqlsrv_ functions or better yet switch to PDO
I am using a linux build server (http://circleci.com) for auto builds and testing; however i need to connect to a MSSQL server. I can develop on windows fine and connect using the MS php SQLSVR drivers, but i cannot connect on the Linux build server as the drivers are windows only.
My Question is this: is there a single way to connect to MSSQL server via php for both windows and linux? tried odbc but then you need bdlib and FreeTDS on linux - this would constitute a code change thus meaning the tests are not 100%, for example on windows environment it would use odbc:{SQL Server} and on linux it would be odbc:FreeTDS
It just doesn't seem right to have a check to see what system is being used and then choose the corresponding db connection string.
I am using PHP 5.5.1
No, there is not a single way however it would be trivial to do something like this:
if ('Linux' === PHP_OS){
$pdo = new PDO("dblib:dbname=$database_name;host=$database_server", $username, $password);
}else{
// $pdo = whatever you're using on your Windows box now.
}
You will need to set up your odbc.ini, odbcinst.ini and freetds.conf files on the Linux server as well.
This line of code new PDO (" odbc: Driver = {Microsoft Excel Driver (*. Xls, *. Xlsx, *. Xlsm, *. Xlsb)}; DBQ = works fine if my web server is on Windows, but Ubuntu is not true, I can not find how to install the PDO driver for Excel in PHP 5.
Thanks for taking the time on this question.
PHP can manipulate COM objects.
Only in Windows plataform you can do things like:
<?php
$word = new COM("C:\docs\word.doc");
?>
This will create a new instance if there is no running instance available or it will return a handle to the running instance, if available. That's because Windows have ODBC driver working with COM resources.
In your case try use http://www.unixodbc.org/ in Linux, Excel driver are support by this project by http://www.easysoft.com.
The bad news are RMS driver from EasySoft it's not free :(
I'm considering changing some PHP code to use PDO for database access instead of mysqli (because the PDO syntax makes more sense to me and is database-agnostic). To do that, I'd need both methods to work while I'm making the changeover.
My problem is this: so far, either one or the other method will crash Apache.
Right now I'm using XAMPP in Windows XP, and PHP Version 5.2.8. Mysqli works fine, and so does this:
$dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
echo 'Connected to database';
$sql = "SELECT * FROM `employee`";
But this line makes Apache crash:
$dbc->query($sql);
I don't want to redo my entire Apache or XAMPP installation, but I'd like for PDO to work. So I tried updating libmysql.dll from here, as oddvibes recommended here. That made my simple PDO query work, but then mysqli queries crashed Apache.
(I also tried the suggestion after that one, to update php_pdo_mysql.dll and php_pdo.dll, to no effect.)
Test Case
I created this test script to compare PDO vs mysqli. With the old copy of libmysql.dll, it crashes if $use_pdo is true and doesn't if it's false. With the new copy of libmysql.dll, it's the opposite.
if ($use_pdo){
$dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
echo 'Connected to database<br />';
$sql = "SELECT * FROM `employee`";
$dbc->query($sql);
foreach ($dbc->query($sql) as $row){
echo $row['firstname'] . ' ' . $row['lastname'] . "<br>\n";
}
}
else {
$dbc = #mysqli_connect($hostname, $username, $password, $dbname) OR die('Could not connect to MySQL: ' . mysqli_connect_error());
$sql = "SELECT * FROM `employee`";
$result = #mysqli_query($dbc, $sql) or die(mysqli_error($dbc));
while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo $row['firstname'] . ' ' . $row['lastname'] . "<br>\n";
}
}
What does Apache need in order to support both methods of database query?
Not a direct answer, but perhaps it can help you in your search for it:
The legacy mysql extension (The function prefixed with mysql_) is a thin wrapper over libmysqlclient. The new mysqli extension is essentially the same, but it implements some functionality that were introduced in later versions of libmysqlclient. PDO also uses libmysqlclient, but doesn't map it as directly as the other extensions do. This all amounts to 3 different php-extensions that all refer to the same native library. If some of them make assumptions about the version of the library, it might cause them to clash.
I would suggest that you install the newest version of libmysqlclient.dll that you can find and try to disable the legacy mysql extension (if you haven't already).
If you have code that uses mysql extension, you can have mysqli bind to those functions and it should work the same.
Also, make sure that you don't have the new mysqlnd driver installed for some reason. mysqlnd is an alternative implementation of libmysqlclient and it really just makes everything even more complicated.
Yes, it's a big mess.
It seems like all you need is to uncomment the correct extension directives in php.ini, like extension=php_mysqli.dll and extension=php_pdo_mysql.dll.
I never confirmed this with XAMPP, because I got frustrated with it and decided to install Apache, PHP and MySQL individually. In the process, I learned to do the above steps, along with a lot of other things. So I haven't confirmed that this will work with XAMPP, but I don't see why not, unless it doesn't come with the right drivers.
The two drivers (.dll files) in the example directives above are the ones I'm using. I also set extension_dir = "c:/php/ext" in php.ini - you should make sure that path points to the directory where your php extensions are. (Note that one of the nice things about installing these components separately is that I can put PHP in c:\php instead of having it buried several levels deep in c:\xampp.)
If anybody wants to follow along with installing your server components separately, I documented the whole process, with screenshots, on my blog.
same as Why does this pdo::mysql code crash on windows?
but dont have the solution for the moment
Crash happens only on "SELECT * FROM xxx" query() and prepare/execute
The unique solution i found :
Install LibMySQL.DLL FROM 5.0.51a package (working with last 5.1.44 MySQL Version)
http://www.netfulvpc.fr/files/libmysql_dll.zip
Ok, i have a very bad but working solution :p)
Open ext\php_pdo_mysql.dll with an Hex Editor
Search for "83 C3 50" offset 0x000024d5 (in php 5.2.12 vc6)
Replace by 83 C3 "54"
The problem is a bad structure size... (struct pdo_column_data)
I tried to fix that in libmysql.dll but that crash php_mysqli ;)