ted_chou12 Posted December 26, 2006 Share Posted December 26, 2006 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. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 26, 2006 Share Posted December 26, 2006 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. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 sorry, i dont quite understand... ??? could you explain please? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 26, 2006 Share Posted December 26, 2006 you will always usemysql_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? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 i dont need any information, this is a test for if the table exists or not... if not then the inserting fails...oh yeah. so the keyword is exist, how to you code so that it gives you whether the table exists or not? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 here, i think this is what i want, but i dont quite understand it...(found it on google)$res = mysql_query("show table status like '$tablename'")or die(mysql_error());$table_exists = mysql_num_rows($res) == 1; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.