PHP, mySQL and connection to a SQL Database 
Author Message
 PHP, mySQL and connection to a SQL Database

Good Morning News Group,

can anyone tell me if  I am able to write Records to a local SQL Database
from PHP on my Webserver. Maybe a Connection via my SQL.

For example:
I have got a local SQL Server with details of a customer database and a
website where the customers can connect to update their informatons. Now I
would like my Website to write and read the new customers details directly
from/to my local server.

Anyone here with a good idea????

Best regards
Dirk



Wed, 13 Jul 2005 21:34:21 GMT  
 PHP, mySQL and connection to a SQL Database
* Step 1:
connecting to a MySQL server installed on the same computer as the webserver
(localhost)

$server='localhost:3306';
$username='yourusername';
$password='yourpassowrd';

$mySQLlink=mysql_connect($server,$username,$password) or die('Cannot
establish connection to MySQL server.');

* Step 2:
select your database

$table='yourdatabase';

mysql_select_db($table,$mySQLlink) or die("Cannot access required database
:".mysql_error());

* Step 3:
 set up SQL query (using a very arbitrary string scomparison, % = wildcard,
\ characters to protect quote marks in SQL statement, addslashes() function
to protect any quote marks in comparison string.)

$word='hat';
$QuerySQL='SELECT  name,item FROM people WHERE people.item
=\'%'.addslashes($word).'%\'';

* Step 4:
execute SQL query:

  $query=mysql_query($querySQL) or die('Query "'.$querySQL.'" failed.
'.mysql_error());

* Step 5:
read results of query, looping through each record in the resulting set of
records using the while() statement

  while($query_row=mysql_fetch_array($query,MYSQL_ASSOC))
{
  $name=$query_row["name"];
  $item=$query_row["item"];
// process information from query, record by record

Quote:
}

* step 6:
clear query

mysql_free_result($query);

* step 7:
close link to SQL server

mysql_close($mySQLlink);

you can also use the SQL INSERT, UPDATE and DELETE ststements to modify the
contents of a table

To insert new records

$insertSQL='INSERT INTO table (field1,field2) VALUES
('.$number.',\''.$string.'\')';
$insert=mysql_query($insertSQL) or die('Query "'.$insertSQL.'" failed.
'.mysql_error());


Quote:
> Good Morning News Group,

> can anyone tell me if  I am able to write Records to a local SQL Database
> from PHP on my Webserver. Maybe a Connection via my SQL.

> For example:
> I have got a local SQL Server with details of a customer database and a
> website where the customers can connect to update their informatons. Now
I
> would like my Website to write and read the new customers details directly
> from/to my local server.

> Anyone here with a good idea????

> Best regards
> Dirk



Thu, 14 Jul 2005 02:01:57 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Newbie Help with php connection to mysql

2. Newbie Prob with php connection to mysql

3. Passing MySQL connection parameters between PHP files

4. SQL injection - PHP, MySQL, magic_quotes = on

5. SQL Server to MySQL thru PHP

6. Legacy example of showing a status screen for a DNSless connection to an MS SQL database

7. PHP / MySQL / VFP Database

8. Using PHP to transfer data between 2 MySQL databases

9. empty cells in mysql database and PHP

10. oncemore: Connection CommonLisp - SQL-Databases

11. Opening a connection for a Microsoft SQL Server database

12. php mysql sample code php shareware like KB knowledgebase

 

 
Powered by phpBB® Forum Software