Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> if mi się zepsuł, Nie ma $rs'a w mieście
frelo
post
Post #1





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 7.02.2006

Ostrzeżenie: (10%)
X----


  1. <?php
  2.  
  3. function query( $sql ) {
  4.     global $conn;
  5.     $rs = $conn->Execute( $sql );
  6.     print_r( $rs );
  7.     if ( ! $rs ) {
  8.         die( 'error' );
  9.     }
  10.     return $rs;
  11. }
  12.  
  13. ?>
(IMG:http://forum.php.pl/uwaga.gif)
poprawiam
---
nospor



Funkcja jak funkcja, zwraca record set ($rs) ADODB. Ciekawe jest to, że najpierw print_r() wyświetla $rs, a w następnej linijce już tego $rs'a nie i odpala die():

ADORecordSet_mysqli Object ( [databaseType] => mysqli [canSeek] => 1 [dataProvider] => native [fields] => Array ( [sectionId] => 533 [languageId] => 1 [baseVersionId] => 526 [parentId] => 1 [contentTypeId] => 1 [name] => Strona g?ówna [shortDescription] => [longDescription] => [activity] => 1 [toDelete] => 0 [position] => 1 [depth] => 1 ) [blobSize] => 100 [sql] => SELECT * FROM sections where sectionId='533' [EOF] => [emptyTimeStamp] => [emptyDate] => [debug] => [timeCreated] => 0 [bind] => [fetchMode] => 1 [connection] => ADODB_mysqli Object ( [databaseType] => mysqli [dataProvider] => native [hasInsertID] => 1 [hasAffectedRows] => 1 [metaTablesSQL] => SHOW TABLES [metaColumnsSQL] => SHOW COLUMNS FROM %s [fmtTimeStamp] => 'Y-m-d H:i:s' [hasLimit] => 1 [hasMoveFirst] => 1 [hasGenID] => 1 [isoDates] => 1 [sysDate] => CURDATE() [sysTimeStamp] => NOW() [hasTransactions] => [forceNewConnect] => [poorAffectedRows] => 1 [clientFlags] => 0 [substr] => substring [port] => [socket] => [_bindInputArray] => [nameQuote] => ` [_genIDSQL] => update %s set id=LAST_INSERT_ID(id+1); [_genSeqSQL] => create table %s (id int not null) [_genSeq2SQL] => insert into %s values (%s) [_dropSeqSQL] => drop table %s [database] => orzel [host] => localhost [user] => root [password] => rootpass [debug] => [maxblobsize] => 262144 [concat_operator] => + [length] => length [random] => rand() [upperCase] => upper [fmtDate] => 'Y-m-d' [true] => 1 [false] => 0 [replaceQuote] => \' [charSet] => [metaDatabasesSQL] => [uniqueOrderBy] => [emptyDate] => [emptyTimeStamp] => [lastInsID] => [hasTop] => [readOnly] => [genID] => 0 [raiseErrorFn] => [cacheSecs] => 3600 [arrayClass] => ADORecordSet_array [noNullStrings] => [numCacheHits] => 0 [numCacheMisses] => 0 [pageExecuteCountRows] => 1 [uniqueSort] => [leftOuter] => [rightOuter] => [ansiOuter] => [autoRollback] => [fnExecute] => [fnCacheExecute] => [blobEncodeType] => [rsPrefix] => ADORecordSet_ [autoCommit] => 1 [transOff] => 0 [transCnt] => 0 [fetchMode] => [_oldRaiseFn] => [_transOK] => [_connectionID] => mysqli Object ( ) [_errorMsg] => [_errorCode] => [_queryID] => mysqli_result Object ( ) [_isPersistentConnection] => 1 [_evalAll] => [_affected] => [_logsql] => [databaseName] => orzel ) [_numOfRows] => 1 [_numOfFields] => 12 [_queryID] => mysqli_result Object ( ) [_currentRow] => 0 [_closed] => [_inited] => 1 [_obj] => [_names] => [_currentPage] => -1 [_atFirstPage] => [_atLastPage] => [_lastPageNo] => -1 [_maxRecordCount] => 0 [datetime] => [adodbFetchMode] => 2 ) error

Kto to zrozumie ten jest gość. (IMG:http://forum.php.pl/style_emoticons/default/party.gif)

Chyba if mi się zepsuł (IMG:http://forum.php.pl/style_emoticons/default/dry.gif) Wszystko łyka oprócz false. Apache'a restartowałem bez efektu. Działam na Windows 2003.

Ten post edytował frelo 27.03.2006, 13:09:21
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




Moim zdaniem Adiasz wysunął calkiem możliwą teorię. Ty nam nie pokazales jak uzywasz tej funkcji, tylko co masz w srodku. A w przypadky, gdy dostaniesz false, to print_r nic nie zwroci wiec tego nie widac. Wiec ty sie zastanow co piszesz. if dziala bez zarzutu

zeby miec pewnosc zrob se prosty test. wyswietl tą zmienną jeszcze raz przed die(). jesli pojawic ci sie drugi raz tablica, znaczy ze faktycznie if źle dziala. jesli nie, znaczy ze Adiasz ma racje (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

  1. <?php
  2. function query( $sql ) {
  3. global $conn;
  4. $rs = $conn->Execute( $sql );
  5. echo 'Przed IF:';
  6. print_r( $rs );
  7. if ( ! $rs ) {
  8. echo 'W IF:';
  9. print_r( $rs );
  10. die( 'error' );
  11. }
  12. return $rs;
  13. }
  14. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 17.10.2025 - 04:36