Jump to content
php.lv forumi

Nolasīt no datubāzes.


toksiks

Recommended Posts

1: http://lv.php.net/manual/en/function.mysql-connect.php'>http://lv.php.net/manual/en/function.mysql-connect.php

2: http://lv.php.net/manual/en/function.mysql-query.php'>http://lv.php.net/manual/en/function.mysql-query.php

3.1: http://lv.php.net/manual/en/function.mysql-fetch-object.php'>http://lv.php.net/manual/en/function.mysql-fetch-object.php

3.2: http://lv.php.net/manual/en/function.maxdb-fetch-array.php'>http://lv.php.net/manual/en/function.maxdb-fetch-array.php

4: http://lv.php.net/manual/en/function.maxdb-fetch-array.php'>http://lv.php.net/manual/en/function.maxdb-fetch-array.php

4.2: http://lv.php.net/manual/en/control-structures.foreach.php'>http://lv.php.net/manual/en/control-structures.foreach.php

5: http://lv.php.net/manual/en/function.echo.php'>http://lv.php.net/manual/en/function.echo.php

 

DIMMM...? this one? -> http://lv.php.net

Link to comment
Share on other sites

$sql = "
SELECT `id`, `username`, `password`
FROM `users`
";

$query = mysql_query( $sql ) || exit( mysql_error() );

while ( $row = mysql_fetch_assoc( $query ) ) {

echo $row['id'] . ' ' . $row['username'] . ' ' . $row['password'];

}

 

Nu šitā tiks nolasītas visas vērtības katram ierakstam 'users' tabulā. Tikai pirms tam ir jāsavienojas ar serveri un jāizvēlas pareizā datubāze.

 

mysql_connect( 'localhost', 'daGrevis', '123456' );
mysql_select_db( 'datubāze' );

 

Un tad, ja vajag ko citu... teiksim tikai viena ieraksta paroli, piemēram...

 

$sql = "
SELECT `password`
FROM `users`
WHERE `username` = 'daGrevis'
";

$query = mysql_query( $sql ) || exit( mysql_error() );

echo mysql_result( $query, 0 );

 

Googles tante ir Tavs draugs! Un jā, vispār mūsdienās vajadzētu izmantot MySQLi vai PDO, bet šitais ir tikai piemērs.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...