简体   繁体   中英

how to connect and insert and retrieve data from database?

$con = mysql_connect("localhost","music123_sri","password");
 if (!$con) 
  { die('Could not connect: ' . mysql_error()); } 
mysql_select_db("music123_telugu", $con);
 $sql="INSERT INTO xml (File) VALUES (" . mysql_escape_string($xmlString) . ")"; 

$data = mysql_query("SELECT File FROM xml")

 $info = mysql_fetch_array( $data );

can u help me in coding for connecting to database and inserting data and retrieving data

As I wrote in some other answer to one of your questions: please read some introduction on how to use PHP with MySQL. A lot of problems will disappear when you get some sort of understanding on how these pieces fit together.

In your concrete example you have three problems:

  1. Your INSERT -query is never executed as it's never send to the database server
  2. You only retrieve the first row from the result set of your query using mysql_fetch_array()
  3. There is a ; missing - so your code is not even valid PHP

I won't give you a finished code snippet but some advice: carefully read the PHP manual for mysql_query() and mysql_fetch_array() and try to understand how they fit into your code.

尝试在$data = mysql_query("SELECT File FROM xml")之后添加分号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM