Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 200003

Re: [PHP3] [RE] Odbc Help From: TV Karthick Kumar (tvkarthick <email protected>)
Date: 03/31/00

Hi

         Thanks for your reply. I have now managed to work with Ms Access
with PHP 3.0 !. I don't want to take up a risk by using php 4.0 beta. I
know that it didn't work well with mysql database itself.

         Now I am able to connect to the database and as I am slowly
enhancing my scripts I am querying some basic results from a database which
has a list of Companies.

         Almost in all the queries if the result is true something will
happen and if the result if wrong some other thing will happen. I mean, we
have to program it in this / that way. I have also done the same thing.
When a condition has to be implemented we got to use the ' IF- Else'
syntax. Here also I am using a IF- Else syntax, but the IF condition is
executing the IF part and + (in addition) the Else part also. Why is that so ?.

         Here the query and the if part which I have written for a simple
query:

         <?
         echo 'Results are:';
         echo "<br><br>";
         echo "Username --> $username";
         echo "<br><br>";
         echo "Password --> $password";
         echo "<br><br>";

$db = odbc_pconnect("leather","","");

echo "Connected to the database";

echo "<br><br>";

$q="Select * from profile1 where company = '$username'";

$result=odbc_exec($db,$q);

if ($result==true)
{
         odbc_result_all($result);
         echo "<script>alert('working')</script>";
         echo "The company is: $username";
}
else
         echo 'not working';
?>

-- Here I am getting a username and password from a Form (it's uprofile.htm
- html page) and the above script is the target file / action file. I have
only php in this uprofile.php3 file.

         Here I am querying a simple thing and then storing it onto
$result. And then I am checking if $result is true, display all the records
in that table which is been queried just now and if the $result is False or
if the $result goes wrong, it should display ' not working '.

         But in my case, what happens is, whenever I execute this script it
executes the odbc_result_all($result) which I have given in the IF part and
also it's displaying 'not working' in the else part. Why is this so ?.

         Please help me on this...

         Thanks in advance.

-- K

At 10:22 AM 3/31/00 -0300, you wrote:
>Hi,
>This is a summary of the functions one should use to work with ODBC.
>
>int odbc_connect(string dns, strnig username, string password), open
>connection to the odbc, as the dsn is associated to a database, you don't
>have to select a database (as you should with mysql,ms sql, eg.
>mysql_select_db);
>
>int odbc_exec(int conn_id, string query), prepare and execute the query;
>
>int odbc_fetch_row(int result, [int row_number]), go to next row, or to
>row_number if especified, but it don't work with many drivers;
>
>odbc_result(int result, mixed field), retrieve the data from the query,
>mixed field is the desired field number or its name;
>
>close(int conn_id), close connection ;
>
>e.g.
>$conn_id = odbc_connect("my dsn", "guest", "guest"); // in my case, "my
>dsn" is a system dsn, don't know if it work with a
>//user dsn, or a file dsn (think no)
>$result = odbc_exec($conn_id, "select * from students");
>odbc_fetch_row($result); // if there isn't next row return false ( 0 )
>odbc_result($result, 1); // return the data in field #1 of the current row
> //if field #1 name's "student_id", you could use
>odbc_result($result, "student_id")
>odbc_close($conn_id);
>
>For a complete list and/or description of the functions take a look at the
>manual at http://www.php.net
>Hope this help.
>
>P.S. I experienced problem using this with php4 beta3, but it's working fine
>with php3
>
>"A vida é como uma partida de poker, as vezes voce ganha com um par, em
>outras, perde com um 'full house' ".
>Extraido de "Um tok na cuka"
>
>Carlos Andre Marques Moreira
>Senai/Cetae
>camoreira <email protected>
>
>
>--
>PHP 3 Mailing List <http://www.php.net/>
>To unsubscribe, send an empty message to php3-unsubscribe <email protected>
>To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
>To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
>To contact the list administrators, e-mail: php-list-admin <email protected>

-- 
PHP 3 Mailing List <http://www.php.net/>
To unsubscribe, send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
To contact the list administrators, e-mail: php-list-admin <email protected>