cvs: php4 /tests/ odbc-display.php odbc-t1.php odbc-t2.php odbc-t3.php odbc-t4.php odbc-t5.php

From: Date: Sun, 28 May 2000 12:50:19 +0000
Subject: cvs: php4 /tests/ odbc-display.php odbc-t1.php odbc-t2.php odbc-t3.php odbc-t4.php odbc-t5.php
Groups: php.version4 
Request: Send a blank email to php-version4+get-15858@lists.php.net to get a copy of this message
kara Sun May 28 05:50:19 2000 EDT Added files: /php4/tests odbc-display.php odbc-t1.php odbc-t2.php odbc-t3.php odbc-t4.php odbc-t5.php Log: Test scripts for ODBC added Index: php4/tests/odbc-display.php +++ php4/tests/odbc-display.php <?php if(($conn = odbc_connect($dsn, $dbuser, $dbpwd))){ if(($res = odbc_do($conn, "select gif from php_test where id='$id'"))){ odbc_binmode($res, 0); odbc_longreadlen($res, 0); if(odbc_fetch_row($res)){ header("content-type: image/gif"); odbc_result($res, 1); exit; }else{ echo "Error in odbc_fetch_row"; } } else { echo "Error in odbc_do"; } } else { echo "Error in odbc_connect"; } ?> Index: php4/tests/odbc-t1.php +++ php4/tests/odbc-t1.php <HTML> <HEAD> <TITLE>Quick &amp; dirty ODBC test</TITLE> </HEAD> <BODY> <H1>ODBC Test 1 - Connection</H1> <?php if(isset($dbuser)){ echo "Connecting to $dsn as $dbuser\n<P>"; $conn = odbc_connect($dsn,$dbuser,$dbpwd); if(!$conn){ ?> <H2>Error connecting to database! Check DSN, username and password</H2> <?php }else{ ?> <H2>Connection successful</H2> <A HREF="odbc-t2.php<?php echo "?dbuser=$dbuser&dsn=$dsn&dbpwd=$dbpwd" ?>">Proceed to next test</A> | <A HREF="<?php echo $PHP_SELF ?>">Change login information</A> <?php } } else { ?> <EM>You will need permisson to create tables for the following tests!</EM> <form action=odbc-t1.php method=post> <table border=0> <tr><td>Database (DSN): </td><td><input type=text name=dsn></td></tr> <tr><td>User: </td><td><input type=text name=dbuser></td></tr> <tr><td>Password: </td><td><input type=password name=dbpwd></td></tr> </table> <br> <input type=submit value=connect> </form> <?php } ?> </BODY> </HTML> Index: php4/tests/odbc-t2.php +++ php4/tests/odbc-t2.php <HTML> <HEAD> <TITLE>Quick &amp; dirty ODBC test #2</TITLE> </HEAD> <BODY> <H1>ODBC Test 2 - Create table</H1> <?php if(isset($dbuser)){ echo "Connecting to $dsn as $dbuser\n"; $conn = odbc_connect($dsn,$dbuser,$dbpwd); if(!$conn){ ?> <H2>Error connecting to database! Check DSN, username and password</H2> <?php }else{ ?> - OK<p> Dropping table "php3_test" <?php Error_Reporting(0); $res = odbc_exec($conn,"drop table php_test"); if($res){ odbc_free_result($res); } ?> - OK<p> Create table "php_test" <?php error_reporting(1); $res = odbc_exec($conn, 'create table php_test (a char(16), b integer, c float, d varchar(128))'); if($res){ odbc_free_result($res); ?> - OK<p> Table Info:<br> <table> <tr> <th>Name</th> <th>Type</th> <th>Length</th> </tr> <?php $info = odbc_exec($conn,"select * from php_test"); $numfields = odbc_num_fields($info); for($i=1; $i<=$numfields; $i++){ ?> <tr> <td><?php echo odbc_field_name($info, $i) ?></td> <td><?php echo odbc_field_type($info, $i) ?></td> <td><?php echo odbc_field_len($info,$i) ?></td> </tr> <?php } ?> </table> <P> <HR width=50%"> <P> <A HREF="odbc-t3.php<?php echo "?dbuser=$dbuser&dsn=$dsn&dbpwd=$dbpwd" ?>">Proceed to next test</A> | <A HREF="<?php echo $PHP_SELF; ?>">Change login information</A> <?php } } } else { ?> <form action="odbc-t3.php" method=post> <table border=0> <tr><td>Database (DSN): </td><td><input type=text name=dsn></td></tr> <tr><td>User: </td><td><input type=text name=dbuser></td></tr> <tr><td>Password: </td><td><input type=password name=dbpwd></td></tr> </table> <input type=submit value="Continue"> </form> <?php } ?> </BODY> </HTML> Index: php4/tests/odbc-t3.php +++ php4/tests/odbc-t3.php <HTML> <HEAD> <TITLE>Database test #3</TITLE> </HEAD> <BODY> <H1>ODBC Test 3 - Insert records</H1> <?php if(isset($dbuser)){ echo "Connecting to $dsn as $dbuser\n"; $conn = odbc_connect($dsn,$dbuser,$dbpwd); if(!$conn){ ?> <H2>Error connecting to database! Check DSN, username and password</H2> <?php }else{ ?> - OK<p> Clearing table "php_test" <?php error_reporting(0); $res=odbc_exec($conn,"delete from php_test"); odbc_free_result($res); error_reporting(1); ?> - OK<p> Inserting into table "php_test" <?php $sqlfloat = '00.0'; $sqlint = 1000; $stmt = odbc_prepare($conn, "insert into php_test values(?,?,?,?)"); for($i=1; $i<=5; $i++){ $values[0] = "test-$i"; $values[1] = $sqlint + $i; $values[2] = $i . $sqlfloat . $i; $values[3] = "php - values $i"; $ret = odbc_execute($stmt, &$values); } odbc_free_result($stmt); $res = odbc_exec($conn, "select count(*) from php_test"); if($res && (odbc_result($res, 1) == 5)){ odbc_free_result($res); ?> - OK<p> <H3>The table "php_test" should now contain the following values:</H3> <table> <tr> <th>A</th><th>B</th><th>C</th><th>D</th> </tr> <tr> <td>test-1</td><td>1001</td><td>100.01</td><td>php - values 1</td> </tr> <tr> <td>test-2</td><td>1002</td><td>200.02</td><td>php - values 2</td> </tr> <tr> <td>test-3</td><td>1003</td><td>300.03</td><td>php - values 3</td> </tr> <tr> <td>test-4</td><td>1004</td><td>400.04</td><td>php - values 4</td> </tr> <tr> <td>test-5</td><td>1005</td><td>500.05</td><td>php - values 5</td> </tr> </table> <H3>Actual contents of table "php_test":</H3> <?php $res = odbc_exec($conn, "select * from php_test"); odbc_result_all($res); } ?> <p> <HR width="50%"> <p> <A HREF="odbc-t4.php?dbuser=<?php echo "$dbuser&dsn=$dsn&dbpwd=$dbpwd" ?>">Proceed to next test</A> | <A HREF="<?php echo $PHP_SELF ?>">Change login information</A> <?php } } else { ?> <form action=odbc-t3.php method=post> <table border=0> <tr><td>Database: </td><td><input type=text name=dsn></td></tr> <tr><td>User: </td><td><input type=text name=dbuser></td></tr> <tr><td>Password: </td><td><input type=password name=dbpwd></td></tr> </table> <input type=submit value=connect> </form> <?php } ?> </BODY> </HTML> Index: php4/tests/odbc-t4.php +++ php4/tests/odbc-t4.php <HTML> <HEAD> <TITLE>Database test #4</TITLE> </HEAD> <BODY> <H1>ODBC Test 4 - Cursors</H1> <em>The following test requires your ODBC driver to support positioned updates</em><p> <?php if(isset($dbuser)){ echo "Connecting to $dsn as $dbuser\n"; $conn = odbc_connect($dsn,$dbuser,$dbpwd); if(!$conn){ ?> <H2>Error connecting to database! Check DSN, username and password</H2> <?php }else{ ?> - OK<p> Updating table "php_test" <?php odbc_autocommit($conn, 0); if(($result = odbc_do($conn, 'select * from php_test where b>1002 for update'))){ $cursor = odbc_cursor($result); if(($upd = odbc_prepare($conn,"update php_test set a=?, b=? where current of $cursor"))){ while(odbc_fetch_row($result)) { $params[0] = odbc_result($result, 1) . "(*)"; $params[1] = odbc_result($result, 2) + 2000; odbc_execute($upd, $params); } odbc_commit($conn); } } if($result && $upd){ ?> - OK<p> <H3>The table "php_test" should now contain the following values:</H3> <table> <tr> <th>A</th><th>B</th><th>C</th><th>D</th> </tr> <tr> <td>test-1</td><td>1001</td><td>100.01</td><td>php3 - values 1</td> </tr> <tr> <td>test-2</td><td>1002</td><td>200.02</td><td>php - values 2</td> </tr> <tr> <td>test-3(*)</td><td>3003</td><td>300.03</td><td>php - values 3</td> </tr> <tr> <td>test-4(*)</td><td>3004</td><td>400.04</td><td>php - values 4</td> </tr> <tr> <td>test-5(*)</td><td>3005</td><td>500.05</td><td>php - values 5</td> </tr> <tr> <td colspan=4> <small><em><strong>Note:</strong> If you reload this testpage,<br> the three last rows will contain different<br>values in columns A and B</em></small> </td> </tr> </table> <H3>Actual contents of table "php_test":</H3> <?php $res = odbc_exec($conn,"select * from php_test"); odbc_result_all($res); }else{ echo "Your driver obviously doesn't support positioned updates\n<p>"; } ?> <p><HR width="50%"><p> <A HREF="odbc-t5.php?dbuser=<?php echo "$dbuser&dsn=$dsn&dbpwd=$dbpwd"; ?>">Proceed to next test</A> <?php } } else { ?> <form action=odbc-t4.php method=post> <table border=0> <tr><td>Database: </td><td><input type=text name=dsn></td></tr> <tr><td>User: </td><td><input type=text name=dbuser></td></tr> <tr><td>Password: </td><td><input type=password name=dbpwd></td></tr> </table> <input type=submit value=connect> </form> <?php } ?> </BODY> </HTML> Index: php4/tests/odbc-t5.php +++ php4/tests/odbc-t5.php <HTML> <HEAD> <TITLE>Database test #5</TITLE> </HEAD> <BODY> <H1>ODBC Test 5 - Blobs</H1> <?php if(!isset($gif1file) && !isset($display) || ($gif1file == "none" && $gif2file == "none" && $gif3file == "none")){ ?> <H2>Please select the images (gif) you want to put into the database</H2> <FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>" ENCTYPE="multipart/form-data"> Image 1: <INPUT TYPE="file" NAME="gif1file" VALUE="" SIZE="48"><P> Image 2: <INPUT TYPE="file" NAME="gif2file" VALUE="" SIZE="48"><P> Image 3: <INPUT TYPE="file" NAME="gif3file" VALUE="" SIZE="48"><P> Blob database type name: <INPUT TYPE="text" NAME="datatype" VALUE="LONG BYTE" SIZE="32"> <P> <INPUT TYPE="hidden" name="dsn" value="<?php echo $dsn ?>"> <INPUT TYPE="hidden" name="dbuser" value="<?php echo $dbuser ?>"> <INPUT TYPE="hidden" name="dbpwd" value="<?php echo $dbpwd ?>"> <INPUT TYPE="submit" VALUE="Send File(s)"> | <INPUT TYPE="reset" VALUE="reset"> </FORM> </BODY> </HTML> <?php exit; } if(isset($dbuser)){ echo "Connecting to $dsn as $dbuser\n"; $conn = odbc_connect($dsn, $dbuser, $dbpwd); if(!$conn){ ?> <H2>Error connecting to database! Check DSN, username and password</H2> <?php }else{ ?> - OK<p> <?php if(isset($display)){ if(($res = odbc_exec($conn, 'select id from php_test'))){ echo "<H3>Images in database</H3>"; while(odbc_fetch_into($res, &$imgs)){ echo "$imgs[0] : <IMG SRC=\"odbc-display.php?id=$imgs[0]&dbuser=$dbuser&dsn=$dsn&dbpwd=$dbpwd\">\n<P>"; } }else{ echo "Couldn't execute query"; } echo "\n</BODY>\n</HTML>"; exit; } ?> Dropping table "php_test" <?php Error_Reporting(0); $res = odbc_exec($conn, "drop table php_test"); if($res){ odbc_free_result($res); } ?> - OK<p> Creating table "php_test": <?php $res = odbc_exec($conn, "create table php_test (id char(32), gif $datatype)"); if($res){ odbc_free_result($res); ?> - OK<p> Table Info:<br> <table> <tr> <th>Name</th> <th>Type</th> <th>Length</th> </tr> <?php $info = odbc_exec($conn,"select * from php_test"); $numfields = odbc_num_fields($info); for($i=1; $i<=$numfields; $i++){ ?> <tr> <td><?php echo odbc_field_name($info, $i) ?></td> <td><?php echo odbc_field_type($info, $i) ?></td> <td><?php echo odbc_field_len($info,$i) ?></td> </tr> <?php } odbc_free_result($info); ?> </table> Inserting data: <?php echo "$gif1file - $gif2file - $gif3file"; odbc_free_result($res); $res = odbc_prepare($conn, "insert into php_test values(?,?)"); if($gif1file != "none"){ $params[0] = "image1"; $params[1] = "'$gif1file'"; odbc_execute($res, $params); } if($gif2file != "none"){ $params[0] = "image2"; $params[1] = "'$gif2file'"; odbc_execute($res, $params); } if($gif3file != "none"){ $params[0] = "image3"; $params[1] = "'$gif3file'"; odbc_execute($res, $params); } ?> - OK<P> <A HREF="<?php echo "$PHP_SELF?display=y&dbuser=$dbuser&dsn=$dsn&dbpwd=$dbpwd" ?>">Display Images</A> <?php } } } else { ?> <form action=odbc-t5.php method=post> <table border=0> <tr><td>Database: </td><td><input type=text name=dsn></td></tr> <tr><td>User: </td><td><input type=text name=dbuser></td></tr> <tr><td>Password: </td><td><input type=password name=dbpwd></td></tr> </table> <input type=submit value=connect> </form> <?php } ?> </BODY> </HTML>

« previous php.version4 (#15858) next »