HTML5 Canvas
Written by: Simon Sarris
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Web Driver
  3. MVVM
  4. REST
  5. ADO.NET
  1. HTML5
  2. Ajax
  3. jQuery Selectors
  4. CSS Part 1
  5. Git

Link Details

Link 302671 thumbnail
User 519571 avatar

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.
  • 7
  • 2
  • 1841
  • 0

Comments

Add your comment
User 368023 avatar

yakkoh replied ago:

0 votes Vote down Vote up Reply

How do you check the connection with ODBC?

User 519571 avatar

memiso replied ago:

1 votes Vote down Vote up Reply

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);

User 519571 avatar

memiso replied ago:

0 votes Vote down Vote up Reply
User 233461 avatar

antych replied ago:

0 votes Vote down Vote up Reply

don't use old mysql extension

User 519571 avatar

memiso replied ago:

0 votes Vote down Vote up Reply

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.

User 233461 avatar

antych replied ago:

0 votes Vote down Vote up Reply

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?

User 519571 avatar

memiso replied ago:

0 votes Vote down Vote up Reply

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.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (7)



Voters Against This Link (2)