Jump to content

mysql, connecting to the table


ted_chou12

Recommended Posts

what do I have to include if i only want to connect to the table in mysql, no entry or updates, just simply connection to see if it works or not?
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
this is the previous (connect to mysql, and the database, but i wish i can connect to the table as well)
THanks, ted.
Link to comment
https://forums.phpfreaks.com/topic/31884-mysql-connecting-to-the-table/
Share on other sites

a connection is a connection - no matter if you are just reading from a table or making changes - you will use the same code to connect. You select a database to work with NOT a table and then simply query the relevant table within teh database.
you will always use

mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

(or similar - pconnect, mysqli etc etc). TEST is the name of the database NOT the table.

The localhost, admin and 1admin are your connection details host, username, password - these will more than likely change on a  per site basis.

thats it. That makes a connection.

After that you will query each table(s) for what ever info you need.
[code]<?php
$qry = "SELECT * FROM `users` WHERE `password`= '" . sha1($_POST['password'] . "'";
$qry = mysql_query($qry);

...

?>
[/code]

Hows that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.