[php worldpress] PHP query to SQL server database (wordpress)

 

[Question]

I am trying to communicate to a MSSQL Server database with PHP from a woocommerce website (to fetch data like products, categories etc.). But I get no results, here is my code:

$connectionInfo = array( "UID"=>$uid,                            
                             "PWD"=>$pwd,                            
                             "Database"=>$databaseName); 
$conn = sqlsrv_connect( $serverName, $connectionInfo);  

$tsql = "SELECT * FROM eshopItemsTable";

$stmt = sqlsrv_query($conn, $tsql);
//uncomment to get some results : $table = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
while( $table = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) ) { 
    print_r($table);
        
}
sqlsrv_free_stmt( $stmt);  
sqlsrv_close( $conn); 

with this code it prints nothing. But if I uncomment the line above while then I get some results but I dont get all of them (there are ~2000 items in the db but I get something like 10 items without the first one - which is obvious because I already consume the first row). What is the proper way to get all the results?

 

 

[Answer]

 

Seems something wrong with the while.

The while is ok, but seems like ends before that he had to.

I've looking for some solutions and this man had the same problem:

SQLSRV doesn't fetch all rows

First of all gets the num of results:

$result_num = sqlsrv_num_rows( $result_count_res ); 

And then use a for instead of a while.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

for($i = 0; $i < $result_num; $i++){
            $data[] = sqlsrv_fetch_array( $result_res, SQLSRV_FETCH_ASSOC);
        }

Consider also, a time out. Because you are attacking to another server...

 

 

[출처] https://stackoverflow.com/questions/67391986/php-query-to-sql-server-database-wordpress

 

 

 

 

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
27 [wordpress, 워드프레스] 워드프레스로 쉽게 랜딩 페이지 만들기 (feat. 엘리멘터, GeneratePress, Divi) file 졸리운_곰 2024.12.20 545
26 [wordpress, 워드프레스] WordPress 페이지또는 글에 별도 CSS와 JavaScript 추가하기 file 졸리운_곰 2024.12.19 354
25 [wordpress 플러그인] 코스모스팜. 회원관리 1.메뉴에 로그인 넣기 file 졸리운_곰 2024.08.25 513
24 [wordpress 플러그인] WP-Members로 회원제 사이트 만들기 file 졸리운_곰 2024.08.25 749
23 [php worldpress] 워드프레스 새 서버 이전시 페이지 안나오는 문제 : How to Rewrite URLs with mod_rewrite for Apache on Ubuntu 20.04 file 졸리운_곰 2024.08.07 774
» [php worldpress] PHP query to SQL server database (wordpress) 졸리운_곰 2024.07.28 503
21 [php worldpress] [위 에]wordpress 사용자 암호 화 원리 및 알고리즘 분석 졸리운_곰 2022.04.11 377
20 [wordpress] WPForms 워드프레스 폼빌더 사용법 file 졸리운_곰 2021.04.25 1715
19 [wordpress][워드프레스] 워드프레스에서 wpdb를 사용한 CRUD 작업 예 졸리운_곰 2021.04.15 356
18 워드프레스에서 wpdb를 사용한 CRUD 작업 예 졸리운_곰 2021.01.12 459
17 워드프레스 – CRUD file 졸리운_곰 2021.01.02 501
16 워드프레스 데이터베이스 들여다보기. file 졸리운_곰 2020.08.04 672
15 워드프레스 플러그인과 테마 비교 - 사이트별 플러그인 만들기 졸리운_곰 2020.04.21 501
14 워드프레스에서 js 스크립트 파일과 스타일시트를 올바르게 로드하는 방법 졸리운_곰 2020.04.21 735
13 워드프레스 플러그인 만들기 file 졸리운_곰 2020.04.21 499
12 워드프레스 숏코드: 완벽 가이드 file 졸리운_곰 2020.04.21 513
11 워드프레스 페이지 분석 file 졸리운_곰 2019.11.19 515
10 내가 본 워드프레스 핵심 구조 및 기능 (Wordpress Architecture and Function) file 졸리운_곰 2019.11.19 452
9 Embedding three.js in WordPress 워드프레스에서 three.js 사용 졸리운_곰 2019.11.08 517
8 How to Super Charge your WordPress with Microservices 워드프레스 마이크로서비스 file 졸리운_곰 2019.11.03 373
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED