SkyD Posted July 14, 2005 Report Share Posted July 14, 2005 Vnk testējot ir šāda padarīšana: <? $link = mysql_connect("localhost", "root", "") or die ("<b>Nevar savienoties ar datu baazi!</b>"); mysql_select_db ("reg") or die ("<b>Taadu datu baazi neatradu;pPP</b>"); ?> <?php // This could be supplied by a user, for example $firstname = 'fred'; $lastname = 'fox'; // Formulate Query // This is the best way to perform a SQL query // For more examples, see mysql_real_escape_string() $query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'", mysql_real_escape_string($firstname), mysql_real_escape_string($lastname)); // Perform Query $result = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } // Use result // Attempting to print $result won't allow access to information in the resource // One of the mysql result functions must be used // See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc. while ($row = mysql_fetch_assoc($result)) { echo $row['firstname']; echo $row['lastname']; echo $row['address']; echo $row['age']; } // Free the resources associated with the result set // This is done automatically at the end of the script mysql_free_result($result); ?> Un izmet šo: Invalid query: Table 'reg.friends' doesn't exist Whole query: SELECT firstname, lastname, address, age FROM friends WHERE firstname='fred' AND lastname='fox' Kā ir jaizveido tā reg.friends tabula?? nu reg man ir tā pati mape, kas atrod MySQL datos.. Plz pastāstiet, jo gribu apgūt to lietu ar MySQL tabulām.. Link to comment Share on other sites More sharing options...
Kristabs Posted July 14, 2005 Report Share Posted July 14, 2005 Start - Run - cmd /celsh/uz/mysql_diru/bin/mysql.exe -u logins -p -p ir tad, ja gribi lai tev pasw prasa. taalaak jau dialogs ar mysql serveri: create database reg; use reg; create table friends ( `firstname` varchar (250) NULL , `lastname` varchar (250) NULL , `address` varchar (250) NULL , `age` varchar (250) NULL ); Link to comment Share on other sites More sharing options...
SkyD Posted July 14, 2005 Author Report Share Posted July 14, 2005 (edited) tas kods man ir jaliek ieksh, piem fails.php failaa?? .. iebaazu tur ieksh vinju, bet izmet: "Parse error: parse error, unexpected T_STRING in d:\lapa\m.php on line 3" 3line - create database reg; Varbūt var kautkā sīkāk šitās štelles paskaidrot?? Būtu baig lab=] Edited July 14, 2005 by SkyD Link to comment Share on other sites More sharing options...
Kristabs Posted July 14, 2005 Report Share Posted July 14, 2005 (edited) Pamēģini šitā: <? $hostname="localhost"; $mysql_login="root"; $mysql_password=""; if ($db = mysql_connect("$hostname", "$mysql_login" , "$mysql_password")) { echo "mysql piekonekteets<br>"; } else { echo "dirsaa mati, nevar piekonekteeties pie mysql<br>"; } $q = mysql_query("create database reg"); if($q){ echo "datubaaze izveidota taisam teiblu<br>"; } if (!(mysql_select_db("reg",$db))) { echo "nav kaartiibaa ar DB<br>"; } else { $q= mysql_query("create table friends ( `firstname` varchar (250) NULL , `lastname` varchar (250) NULL , `address` varchar (250) NULL , `age` varchar (250) NULL )")or die(mysql_error()); if($q){ echo "teibls izveidots<br>";} } ?> Edited July 14, 2005 by Kristabs Link to comment Share on other sites More sharing options...
Delfins Posted July 14, 2005 Report Share Posted July 14, 2005 tas kods man ir jaliek ieksh, piem fails.php failaa?? .. iebaazu tur ieksh vinju, bet izmet: "Parse error: parse error, unexpected T_STRING in d:\lapa\m.php on line 3"3line - create database reg; Varbūt var kautkā sīkāk šitās štelles paskaidrot?? Būtu baig lab=] 19382[/snapback] mueh. kāpēc jālie kodēt DB appus ja nevar pat SQL no koda atšķirt :) Link to comment Share on other sites More sharing options...
SkyD Posted July 15, 2005 Author Report Share Posted July 15, 2005 Kristabs, tnx... Link to comment Share on other sites More sharing options...
Kristabs Posted July 15, 2005 Report Share Posted July 15, 2005 bet kaa delfiins mineeja, ir jaaiebrauc atshkjiriibaa starp php un sql. sql ir cita valoda, ar kuru notiek dialogs ar mysql serveri. ar php mees tikai lietojam dazhas funkcijas, kas ljauj padot sql fraazi mysql serverim. respektiivi, tas, kas ir ieksh mysql_query("te naak sql"). buus jaapalasa manuaalji kautkaadi un jaaizprot arii DB uzbuuve un straadaashanas principi, un tad jau vareesi kautko saakt rakstiit pats. Link to comment Share on other sites More sharing options...
Recommended Posts