By memiso
via memiso.com
Published: Nov 25 2009 / 05:11
We can use mysql_connect and mysql_select_db functions to create our connections. For closing the connections there is mysql_close function. These are basic functions of managing connections in PHP. There are also a lot of classes made by developers for free.



Comments
yakkoh replied ago:
How do you check the connection with ODBC?
memiso replied ago:
you can use this code to check the connection:
$mssql_conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$localhost;Database=$mssqldb;", $memisologin, $memiso_pass);
if (odbc_error($mssql_conn))
{
echo odbc_errormsg($mssql_conn);
}
odbc_close($mssql_conn);
Also, you don't have to specify the connection_id in odbc_error() function. In this case the last connection will be tested.. I mean:
$mssql_conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$localhost;Database=$mssqldb;", $memisologin, $memiso_pass);
if (odbc_error())
{
echo odbc_errormsg();
}
odbc_close($mssql_conn);
memiso replied ago:
http://www.memiso.com/checking-database-connections-and-getting-errors-in-php.html
you can take a look at here for details.
antych replied ago:
don't use old mysql extension
memiso replied ago:
I complately agree with you but there are lots of developers which are still using odbc. That's why we need to give solutions for them. Giving informations about old extensions doesn't mean we won't use the new extensions. Of course, we are going to write articles about PDO and whatever comes up. Please be broad-minded and constructive, not destructive.
antych replied ago:
What odbc has to do with it? Mysqli (i for improved) has been around for over 5 years, PDO is just another option. I don't know how you can blog about connecting to mysql without mentioning those 2 extensions. Your article is harmful to any potential PHP developers who will assume that mysql_* is a preferred way to do it.
btw how can you completely agree with me and downvote my comment at the same time and call it destructive? What sort of twisted logic is that?
memiso replied ago:
First of all, this is not a twisted logic. I wanted to vote up your comment but i voted down by mistake:) then i realized but i couldn't change it. That's my fault.
However, i think i couldn't expressed myself clearly. This article shows only one way to connect databases. I will write about new techniques too.. Yes, i put it because this is a new blog and i want to share every method that i know.. And i assume that you didn't read the article properly because i have said :
... These are basic functions of managing connections in PHP. There are also a lot of classes made by developers for free...
And don't worry, i will mention them soon.This blog is not my only work so i have no enough time. I dont want to argue or be obstinate with each other, but if you are exprienced at PHP ( i think so) please write your advices and ideas more detailed, so more people can benefit from that.. In the end, I meant you might to choose constructive wording. That's all.
Voters For This Link (7)
Voters Against This Link (2)